<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QSessionManager Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QSessionManager Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QSessionManager class provides access to the session
manager. <a href="#details">More...</a></p>

<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qsessionmanager.html#RestartHint-enum">RestartHint</a></b> { RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever }</li></ul><h3>Methods</h3><ul><li><div class="fn" />bool <b><a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsessionmanager.html#cancel">cancel</a></b> (<i>self</i>)</li><li><div class="fn" />QStringList <b><a href="qsessionmanager.html#discardCommand">discardCommand</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsessionmanager.html#isPhase2">isPhase2</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsessionmanager.html#release">release</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsessionmanager.html#requestPhase2">requestPhase2</a></b> (<i>self</i>)</li><li><div class="fn" />QStringList <b><a href="qsessionmanager.html#restartCommand">restartCommand</a></b> (<i>self</i>)</li><li><div class="fn" />RestartHint <b><a href="qsessionmanager.html#restartHint">restartHint</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsessionmanager.html#sessionId">sessionId</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsessionmanager.html#sessionKey">sessionKey</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsessionmanager.html#setDiscardCommand">setDiscardCommand</a></b> (<i>self</i>, QStringList)</li><li><div class="fn" /><b><a href="qsessionmanager.html#setManagerProperty">setManagerProperty</a></b> (<i>self</i>, QString&#160;<i>name</i>, QString&#160;<i>value</i>)</li><li><div class="fn" /><b><a href="qsessionmanager.html#setManagerProperty-2">setManagerProperty</a></b> (<i>self</i>, QString&#160;<i>name</i>, QStringList&#160;<i>value</i>)</li><li><div class="fn" /><b><a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a></b> (<i>self</i>, QStringList)</li><li><div class="fn" /><b><a href="qsessionmanager.html#setRestartHint">setRestartHint</a></b> (<i>self</i>, RestartHint)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSessionManager class provides access to the session
manager.</p>
<p>A session manager in a desktop environment (in which Qt GUI
applications live) keeps track of a session, which is a group of
running applications, each of which has a particular state. The
state of an application contains (most notably) the documents the
application has open and the position and size of its windows.</p>
<p>The session manager is used to save the session, e.g., when the
machine is shut down, and to restore a session, e.g., when the
machine is started up. We recommend that you use <a href="qsettings.html">QSettings</a> to save an application's settings,
for example, window positions, recently used files, etc. When the
application is restarted by the session manager, you can restore
the settings.</p>
<p>QSessionManager provides an interface between the application
and the session manager so that the program can work well with the
session manager. In Qt, session management requests for action are
handled by the two virtual functions <a href="qapplication.html#commitData">QApplication.commitData</a>() and
<a href="qapplication.html#saveState">QApplication.saveState</a>(). Both
provide a reference to a session manager object as argument, to
allow the application to communicate with the session manager. The
session manager can only be accessed through these functions.</p>
<p>No user interaction is possible <i>unless</i> the application
gets explicit permission from the session manager. You ask for
permission by calling <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>()
or, if it is really urgent, <a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a>().
Qt does not enforce this, but the session manager may.</p>
<p>You can try to abort the shutdown process by calling <a href="qsessionmanager.html#cancel">cancel</a>(). The default
commitData() function does this if some top-level window rejected
its closeEvent().</p>
<p>For sophisticated session managers provided on Unix/X11,
QSessionManager offers further possibilities to fine-tune an
application's session management behavior: <a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a>(),
<a href="qsessionmanager.html#setDiscardCommand">setDiscardCommand</a>(),
<a href="qsessionmanager.html#setRestartHint">setRestartHint</a>(),
<a href="qobject.html#setProperty">setProperty</a>(), <a href="qsessionmanager.html#requestPhase2">requestPhase2</a>(). See the
respective function descriptions for further details.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="RestartHint-enum" />QSessionManager.RestartHint</h3><p>This enum type defines the circumstances under which this
application wants to be restarted by the session manager. The
current values are:</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign">
<tt>QSessionManager.RestartIfRunning</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">If the application is still running when the
session is shut down, it wants to be restarted at the start of the
next session.</td>
</tr>
<tr>
<td class="topAlign"><tt>QSessionManager.RestartAnyway</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">The application wants to be started at the
start of the next session, no matter what. (This is useful for
utilities that run just after startup and then quit.)</td>
</tr>
<tr>
<td class="topAlign">
<tt>QSessionManager.RestartImmediately</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">The application wants to be started
immediately whenever it is not running.</td>
</tr>
<tr>
<td class="topAlign"><tt>QSessionManager.RestartNever</tt></td>
<td class="topAlign"><tt>3</tt></td>
<td class="topAlign">The application does not want to be restarted
automatically.</td>
</tr>
</table>
<p>The default hint is <tt>RestartIfRunning</tt>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="allowsErrorInteraction" />bool QSessionManager.allowsErrorInteraction (<i>self</i>)</h3><p>Returns true if error interaction is permitted; otherwise
returns false.</p>
<p>This is similar to <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>(),
but also enables the application to tell the user about any errors
that occur. Session managers may give error interaction requests
higher priority, which means that it is more likely that an error
interaction is permitted. However, you are still not guaranteed
that the session manager will allow interaction.</p>
<p><b>See also</b> <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>(),
<a href="qsessionmanager.html#release">release</a>(), and <a href="qsessionmanager.html#cancel">cancel</a>().</p>


<h3 class="fn"><a name="allowsInteraction" />bool QSessionManager.allowsInteraction (<i>self</i>)</h3><p>Asks the session manager for permission to interact with the
user. Returns true if interaction is permitted; otherwise returns
false.</p>
<p>The rationale behind this mechanism is to make it possible to
synchronize user interaction during a shutdown. Advanced session
managers may ask all applications simultaneously to commit their
data, resulting in a much faster shutdown.</p>
<p>When the interaction is completed we strongly recommend
releasing the user interaction semaphore with a call to <a href="qsessionmanager.html#release">release</a>(). This way, other
applications may get the chance to interact with the user while
your application is still busy saving data. (The semaphore is
implicitly released when the application exits.)</p>
<p>If the user decides to cancel the shutdown process during the
interaction phase, you must tell the session manager that this has
happened by calling <a href="qsessionmanager.html#cancel">cancel</a>().</p>
<p>Here's an example of how an application's <a href="qapplication.html#commitData">QApplication.commitData</a>() might
be implemented:</p>
<pre class="cpp">
 <span class="type">void</span> MyApplication<span class="operator">.</span>commitData(<span class="type"><a href="qsessionmanager.html">QSessionManager</a></span><span class="operator">&amp;</span> manager)
 {
     <span class="keyword">if</span> (manager<span class="operator">.</span>allowsInteraction()) {
         <span class="type">int</span> ret <span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">.</span>warning(
                     mainWindow<span class="operator">,</span>
                     tr(<span class="string">"My Application"</span>)<span class="operator">,</span>
                     tr(<span class="string">"Save changes to document?"</span>)<span class="operator">,</span>
                     <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">.</span>Save <span class="operator">|</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">.</span>Discard <span class="operator">|</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">.</span>Cancel);

         <span class="keyword">switch</span> (ret) {
         <span class="keyword">case</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">.</span>Save:
             manager<span class="operator">.</span>release();
             <span class="keyword">if</span> (<span class="operator">!</span>saveDocument())
                 manager<span class="operator">.</span>cancel();
             <span class="keyword">break</span>;
         <span class="keyword">case</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">.</span>Discard:
             <span class="keyword">break</span>;
         <span class="keyword">case</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">.</span>Cancel:
         <span class="keyword">default</span>:
             manager<span class="operator">.</span>cancel();
         }
     } <span class="keyword">else</span> {
         <span class="comment">// we did not get permission to interact, then</span>
         <span class="comment">// do something reasonable instead</span>
     }
 }
</pre>
<p>If an error occurred within the application while saving its
data, you may want to try <a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a>()
instead.</p>
<p><b>See also</b> <a href="qapplication.html#commitData">QApplication.commitData</a>(),
<a href="qsessionmanager.html#release">release</a>(), and <a href="qsessionmanager.html#cancel">cancel</a>().</p>


<h3 class="fn"><a name="cancel" />QSessionManager.cancel (<i>self</i>)</h3><p>Tells the session manager to cancel the shutdown process.
Applications should not call this function without asking the user
first.</p>
<p><b>See also</b> <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>()
and <a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a>().</p>


<h3 class="fn"><a name="discardCommand" />QStringList QSessionManager.discardCommand (<i>self</i>)</h3><p>Returns the currently set discard command.</p>
<p>To iterate over the list, you can use the <a href="containers.html#foreach">foreach</a> pseudo-keyword:</p>
<pre class="cpp">
 <a href="qtcore.html#foreach">foreach</a> (<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>command<span class="operator">,</span> mySession<span class="operator">.</span>discardCommand())
     do_something(command);
</pre>
<p><b>See also</b> <a href="qsessionmanager.html#setDiscardCommand">setDiscardCommand</a>(),
<a href="qsessionmanager.html#restartCommand">restartCommand</a>(),
and <a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a>().</p>


<h3 class="fn"><a name="isPhase2" />bool QSessionManager.isPhase2 (<i>self</i>)</h3><p>Returns true if the session manager is currently performing a
second session management phase; otherwise returns false.</p>
<p><b>See also</b> <a href="qsessionmanager.html#requestPhase2">requestPhase2</a>().</p>


<h3 class="fn"><a name="release" />QSessionManager.release (<i>self</i>)</h3><p>Releases the session manager's interaction semaphore after an
interaction phase.</p>
<p><b>See also</b> <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>()
and <a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a>().</p>


<h3 class="fn"><a name="requestPhase2" />QSessionManager.requestPhase2 (<i>self</i>)</h3><p>Requests a second session management phase for the application.
The application may then return immediately from the <a href="qapplication.html#commitData">QApplication.commitData</a>() or
<a href="qapplication.html#saveState">QApplication.saveState</a>()
function, and they will be called again once most or all other
applications have finished their session management.</p>
<p>The two phases are useful for applications such as the X11
window manager that need to store information about another
application's windows and therefore have to wait until these
applications have completed their respective session management
tasks.</p>
<p><b>Note:</b> If another application has requested a second phase
it may get called before, simultaneously with, or after your
application's second phase.</p>
<p><b>See also</b> <a href="qsessionmanager.html#isPhase2">isPhase2</a>().</p>


<h3 class="fn"><a name="restartCommand" />QStringList QSessionManager.restartCommand (<i>self</i>)</h3><p>Returns the currently set restart command.</p>
<p>To iterate over the list, you can use the <a href="containers.html#foreach">foreach</a> pseudo-keyword:</p>
<pre class="cpp">
 <a href="qtcore.html#foreach">foreach</a> (<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>command<span class="operator">,</span> mySession<span class="operator">.</span>restartCommand())
     do_something(command);
</pre>
<p><b>See also</b> <a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a>()
and <a href="qsessionmanager.html#restartHint">restartHint</a>().</p>


<h3 class="fn"><a name="restartHint" /><a href="qsessionmanager.html#RestartHint-enum">RestartHint</a> QSessionManager.restartHint (<i>self</i>)</h3><p>Returns the application's current restart hint. The default is
<tt>RestartIfRunning</tt>.</p>
<p><b>See also</b> <a href="qsessionmanager.html#setRestartHint">setRestartHint</a>().</p>


<h3 class="fn"><a name="sessionId" />QString QSessionManager.sessionId (<i>self</i>)</h3><p>Returns the identifier of the current session.</p>
<p>If the application has been restored from an earlier session,
this identifier is the same as it was in the earlier session.</p>
<p><b>See also</b> <a href="qsessionmanager.html#sessionKey">sessionKey</a>() and <a href="qapplication.html#sessionId">QApplication.sessionId</a>().</p>


<h3 class="fn"><a name="sessionKey" />QString QSessionManager.sessionKey (<i>self</i>)</h3><p>Returns the session key in the current session.</p>
<p>If the application has been restored from an earlier session,
this key is the same as it was when the previous session ended.</p>
<p>The session key changes with every call of commitData() or
saveState().</p>
<p><b>See also</b> <a href="qsessionmanager.html#sessionId">sessionId</a>() and <a href="qapplication.html#sessionKey">QApplication.sessionKey</a>().</p>


<h3 class="fn"><a name="setDiscardCommand" />QSessionManager.setDiscardCommand (<i>self</i>, QStringList)</h3><p>Sets the discard command to the given <i>list</i>.</p>
<p><b>See also</b> <a href="qsessionmanager.html#discardCommand">discardCommand</a>() and
<a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a>().</p>


<h3 class="fn"><a name="setManagerProperty" />QSessionManager.setManagerProperty (<i>self</i>, QString&#160;<i>name</i>, QString&#160;<i>value</i>)</h3><p>Low-level write access to the application's identification and
state record are kept in the session manager.</p>
<p>The property called <i>name</i> has its value set to the string
list <i>value</i>.</p>


<h3 class="fn"><a name="setManagerProperty-2" />QSessionManager.setManagerProperty (<i>self</i>, QString&#160;<i>name</i>, QStringList&#160;<i>value</i>)</h3><p>This is an overloaded function.</p>
<p>Low-level write access to the application's identification and
state records are kept in the session manager.</p>
<p>The property called <i>name</i> has its value set to the string
<i>value</i>.</p>


<h3 class="fn"><a name="setRestartCommand" />QSessionManager.setRestartCommand (<i>self</i>, QStringList)</h3><p>If the session manager is capable of restoring sessions it will
execute <i>command</i> in order to restore the application. The
command defaults to</p>
<pre class="cpp">
 appname <span class="operator">-</span>session id
</pre>
<p>The <tt>-session</tt> option is mandatory; otherwise <a href="qapplication.html">QApplication</a> cannot tell whether it has
been restored or what the current session identifier is. See
<a href="qapplication.html#isSessionRestored">QApplication.isSessionRestored</a>()
and <a href="qapplication.html#sessionId">QApplication.sessionId</a>() for
details.</p>
<p>If your application is very simple, it may be possible to store
the entire application state in additional command line options.
This is usually a very bad idea because command lines are often
limited to a few hundred bytes. Instead, use <a href="qsettings.html">QSettings</a>, temporary files, or a database for
this purpose. By marking the data with the unique <a href="qsessionmanager.html#sessionId">sessionId</a>(), you will be able
to restore the application in a future session.</p>
<p><b>See also</b> <a href="qsessionmanager.html#restartCommand">restartCommand</a>(),
<a href="qsessionmanager.html#setDiscardCommand">setDiscardCommand</a>(),
and <a href="qsessionmanager.html#setRestartHint">setRestartHint</a>().</p>


<h3 class="fn"><a name="setRestartHint" />QSessionManager.setRestartHint (<i>self</i>, <a href="qsessionmanager.html#RestartHint-enum">RestartHint</a>)</h3><p>Sets the application's restart hint to <i>hint</i>. On
application startup, the hint is set to
<tt>RestartIfRunning</tt>.</p>
<p><b>Note:</b> These flags are only hints, a session manager may
or may not respect them.</p>
<p>We recommend setting the restart hint in <a href="qapplication.html#saveState">QApplication.saveState</a>() because
most session managers perform a checkpoint shortly after an
application's startup.</p>
<p><b>See also</b> <a href="qsessionmanager.html#restartHint">restartHint</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.9.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2011</td><td align="right" width="25%">Qt&#160;4.8.0</td></tr></table></div></address></body></html>